import {
	API_URL,
	IM_API_URL
} from '@/common/common.js';


export function createCoversation(fromUserId, toUserId) {
	let url = "/im-service/im/create/group"
	let data = {
        ownerId: fromUserId,
        members: [fromUserId, toUserId]
      }
	return request(url, "POST", data);
}


function request(url, method, data) {
	return new Promise((resolve, reject) => {
		const token = uni.getStorageSync('token');
		uni.request({
			url: IM_API_URL + '/' + url,
			method: method,
			data: data,
			header: {
				'Authorization': token,
				'content-type': 'application/json'
			},
			success: (res) => {
				if (res.statusCode === 200) {
					resolve(res.data);
				} else {
					reject(res);
				}
			},
			fail: (err) => {
				reject(err);
			}
		});
	});
}


export default {createCoversation}
